package de.pelizaeus.app;



import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class CafeteriaFragment extends Fragment {

    private List<Cafeteria> cafeteria = new ArrayList<Cafeteria>();
    View rootView;

    public CafeteriaFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        rootView = inflater.inflate(R.layout.fragment_cafeteria, container, false);
        populateCafeteriaList();
        populateListView();
        return rootView;
    }

    private void populateCafeteriaList() {
        cafeteria.add(new Cafeteria("Backwaren:",""));
        cafeteria.add(new Cafeteria("Amerikaner","0.90€"));
        cafeteria.add(new Cafeteria("Baguettebrötchen","0.55€"));
        cafeteria.add(new Cafeteria("belegtes Baguette","1.80€"));
        cafeteria.add(new Cafeteria("belegtes Ciabattabrötchen","1.80€"));
        cafeteria.add(new Cafeteria("Berliner","0.80€"));
        cafeteria.add(new Cafeteria("Brötchen","0.27€"));
        cafeteria.add(new Cafeteria("Ciabattabrötchen","0.55€"));
        cafeteria.add(new Cafeteria("Cookie","0.90€"));
        cafeteria.add(new Cafeteria("Croissant","0.70€"));
        cafeteria.add(new Cafeteria("Hot-Dog","1.30€"));
        cafeteria.add(new Cafeteria("Käsebrötchen","0.55€"));
        cafeteria.add(new Cafeteria("Körnerbrötchen","0.40€"));
        cafeteria.add(new Cafeteria("Laugenstange","0.65€"));
        cafeteria.add(new Cafeteria("Mandelhörnchen","0.90€"));
        cafeteria.add(new Cafeteria("Milchmäuse","0.60€"));
        cafeteria.add(new Cafeteria("Muffin","0.90€"));
        cafeteria.add(new Cafeteria("Müsliriegel","0.60€"));
        cafeteria.add(new Cafeteria("Nougatring","0.90€"));
        cafeteria.add(new Cafeteria("Nussecke","0.90€"));
        cafeteria.add(new Cafeteria("Plunderteilchen","0.90€"));
        cafeteria.add(new Cafeteria("Quarkinis (5 Stück)","0.80€"));
        cafeteria.add(new Cafeteria("Quarktasche","0.90€"));
        cafeteria.add(new Cafeteria("Rosinenbrötchen","0.60€"));
        cafeteria.add(new Cafeteria("Schokocroissant","0.90€"));
        cafeteria.add(new Cafeteria("Schweineohr","0.90€"));
        cafeteria.add(new Cafeteria("",""));
        cafeteria.add(new Cafeteria("Getränke:",""));
        cafeteria.add(new Cafeteria("Kakao","0.70€"));
        cafeteria.add(new Cafeteria("Orangenlimonade","0.90€ + 0.50€ Pfand"));
        cafeteria.add(new Cafeteria("Sportaktiv","0.90€ + 0.50€ Pfand"));
        cafeteria.add(new Cafeteria("Wasser","0.80€ + 0.50€ Pfand"));

    }

    private void populateListView() {

        ArrayAdapter<Cafeteria> adapter= new MyListAdapter();

        ListView list= (ListView) rootView.findViewById(R.id.CafeteriaListView);

        list.setAdapter(adapter);
    }

    private class MyListAdapter extends ArrayAdapter<Cafeteria> {
        public MyListAdapter() { super(getActivity(), R.layout.cafeteria_item, cafeteria);}

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View itemView = convertView;
            if (itemView == null) {
                itemView = getActivity().getLayoutInflater().inflate(R.layout.cafeteria_item, parent, false);
            }


            Cafeteria currentCafeteria = cafeteria.get(position);

            //view ausfuellen

            //name
            TextView nameText = (TextView)itemView.findViewById(R.id.name);
            nameText.setText(currentCafeteria.getName());

            //preis
            TextView preisText = (TextView)itemView.findViewById(R.id.preis);
            preisText.setText(currentCafeteria.getPreis());

            return itemView;
            //return super.getView(position, convertView, parent);
        }
    }
    private class Cafeteria {
        private String name;
        private String preis;

        Cafeteria(String pName, String pPreis) {
            this.name = pName;
            this.preis = pPreis;
        }

        public String getName(){ return name;}
        public void setName(String name) {
            this.name = name;
        }
        public String getPreis(){return preis;}
    }
}
